//
//  YYLinkShareHandler.m
//  YYLinkShareView
//
//  Created by 云眼科技 on 16/6/6.
//  Copyright © 2016年 CloudEyes. All rights reserved.
//

#import "YYLinkShareHandler.h"
#import "YYLinkShareHeader.h"



@implementation YYLinkShareHandler


#pragma mark -- ***************************** | 微博返回结果 |  *****************************--
-(NSString *)handleWeiboStateWithCode:(WeiboSDKResponseStatusCode)code{
    NSString *result = nil;
    switch (code) {
        case WeiboSDKResponseStatusCodeSuccess:
            result = @"分享成功";
            break;
        case WeiboSDKResponseStatusCodeUserCancel:
            result = @"用户取消发送";
            break;
        case WeiboSDKResponseStatusCodeSentFail:
            result = @"发送失败";
            break;
        case WeiboSDKResponseStatusCodeAuthDeny:
            result = @"授权失败";
            break;
        case WeiboSDKResponseStatusCodeUserCancelInstall:
            result = @"用户取消安装微博客户端";
            break;
        case WeiboSDKResponseStatusCodePayFail:
            result = @"支付失败";
            break;
        case WeiboSDKResponseStatusCodeShareInSDKFailed:
            result = @"分享失败";
            break;
        case WeiboSDKResponseStatusCodeUnsupport:
            result = @"不支持的请求";
            break;

            break;
        default:
            break;
    }
    
    return result;
}


-(NSString *)handleQQStateWithCode:(QQApiSendResultCode)code{
    NSString *message = nil;
    switch (code){
        case EQQAPISENDSUCESS:
            message = @"分享成功";
            break;
        case EQQAPIAPPNOTREGISTED:
            message = @"App未注册";
            break;
        case EQQAPIMESSAGECONTENTINVALID:
            message = @"发送参数错误";
            break;
        case EQQAPIMESSAGECONTENTNULL:
            message = @"发送消息内容为空";
        case EQQAPIMESSAGETYPEINVALID:
            message = @"发送参数错误";            
            break;
        case EQQAPIQQNOTINSTALLED:
            message = @"未安装QQ客户端";
            break;
        case EQQAPIQQNOTSUPPORTAPI:
            message = @"API接口不支持";
            break;
        case EQQAPISENDFAILD:
            message = @"发送失败";
            break;
        case EQQAPIVERSIONNEEDUPDATE:
            message = @"当前QQ版本太低，需要更新";
            break;
        default:
            message = @"异常错误";
            break;
    }
    return message;
}


-(NSString *)handleWeChatStateWithCode:(WXErrCode)code{
    NSString *message = nil;
    switch (code){
        case WXSuccess:
            message = @"分享成功";
            break;
        case WXErrCodeCommon:
            message = @"分享错误";
            break;
        case WXErrCodeAuthDeny:
            message = @"授权失败";
            break;
        case WXErrCodeSentFail:
            message = @"分享失败";
        case WXErrCodeUnsupport:
            message = @"不支持分享";            
            break;
        case WXErrCodeUserCancel:
            message = @"取消了分享";
            break;
        default:
            break;
    }
    return message;
}



#pragma mark -- ***************************** | 获取平台类型 |  *****************************--
-(platformType)handlePlatformWithTitle:(NSString *)title{
    platformType platform;
    if ([title isEqualToString:@"QQ"]){
        platform = platformTypeQQ;
        
    }else if ([title isEqualToString:@"QQ空间"]){
        platform = platformTypeQZone;
        
    }else if ([title isEqualToString:@"微博"]){
        platform = platformTypeWeibo;
        
    }else if ([title isEqualToString:@"微信"]){
        platform = platformTypeWeChat;
        
    }else if ([title isEqualToString:@"朋友圈"]){
        platform = platformTypeCircle;
        
    }
    return platform;
}



-(BOOL)handleOpenURL:(NSURL *)url delegate:(id)delegate{
    NSString *urlType = [url.absoluteString componentsSeparatedByString:@":"].firstObject;
    if ([urlType isEqualToString:UrlType_QQ]) {
        return [TencentOAuth HandleOpenURL:url];
    }else if ([urlType isEqualToString:UrlType_Weibo]){
        return [WeiboSDK handleOpenURL:url delegate:delegate];
    }else if ([urlType isEqualToString:UrlType_WeChat]){
        return [WXApi handleOpenURL:url delegate:delegate];
    }
    return YES;
}



#pragma mark -- ***************************** | 单例 |  *****************************--
+(instancetype)defaultHandler{
    static YYLinkShareHandler *handler = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        handler =[[self alloc] init];
    });
    return handler;
}

@end
